package com.magic.smartcity.view.more.park

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import com.bumptech.glide.Glide
import com.magic.smartcity.R
import com.magic.smartcity.databinding.FragmentParkDetailBinding
import com.magic.smartcity.utils.Constant
import com.magic.smartcity.view.more.viewmodels.ParkViewModel

class ParkDetailFragment : Fragment() {

    private lateinit var binding: FragmentParkDetailBinding
    private var parkId: Int = 0
    private val viewModel by lazy {
        ViewModelProvider(this).get(ParkViewModel::class.java)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        parkId = arguments?.getInt("parkId")!!
        viewModel.getParkById(parkId)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentParkDetailBinding.inflate(layoutInflater)
        initView()
        return binding.root
    }

    private fun initView() {
        viewModel.parkBean.observe(viewLifecycleOwner) {
            binding.parkBean = it
            Glide.with(binding.image).load(Constant.Service_IP + it.imgUrl).error(R.color.gray)
                .into(binding.image)
        }
        binding.goNavigation.setOnClickListener{
            Toast.makeText(requireContext(), "暂时无法导航", Toast.LENGTH_SHORT).show()
        }

    }

}